You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Merge host request headers regardless of casing - #1788
requestHeaders merges the SDK headers and host headers with object spread, so differently cased spellings remain separate object keys. A host returning Authorization alongside the SDK's normalized authorization sends a comma-joined pair of bearer values instead of replacing the old value. Real localhost probes against the current source on both Bun and Node receive HTTP 401 for that request.
HTTP field names are case-insensitive; the Fetch header set operation replaces existing values for the same name. The host already takes precedence when it uses the same casing.
Changes
Merge through Headers and set() instead of a plain object, and remove the unused conversion helper. Extend the existing request-header test to cover the mixed-case override while retaining its exact-body assertion and checking an unrelated SDK header survives. No test file or extra test case is added.
Verification
Extended regression: 0 pass / 1 fail on unmodified main (Bearer tok, Bearer host-token), then 1 pass / 0 fail.
Request-header suite: 4 pass / 1 fail before, then 5 pass / 0 fail. Three related header/provider test files: 36 pass / 0 fail.
Actual localhost HTTP probes on Bun 1.3.14 and Node 24.20.0: the mixed-case hook sends two bearer values before the fix; after it, the server receives only the host value and returns the ok stream. No production backend or model is called. The Node probe bundles the current source for execution; it is not a published SDK build.
SDK typecheck passes with installed native TypeScript 7.0.2. Frozen-lockfile install reports no changes; ESLint has 0 errors / 8 existing resolver/import-order warnings. Raw Prettier checks retain existing CRLF/source style differences; comparison against main finds no new formatting differences.
SDK build remains blocked during declaration-generator loading by the existing ts.sys.getCurrentDirectory error. Binary build and smoke were not run because SDK build is a prerequisite.
Scope / Tradeoffs
Source-audit fix, with no existing issue claimed. Two SDK files only. This preserves the existing host-overrides-default policy while applying it consistently across casing; it does not add a new authentication policy or credential store. Existing hook omission/error behavior and the BYOK exclusion remain covered by the current tests.
Good catch. The root cause is real: plain object spread merges headers by exact key string, so authorization (from the SDK) and Authorization (from a host hook) coexist as separate keys, and when the merged object is eventually normalized into a Headers instance (or sent raw), you get a comma-joined pair of bearer tokens instead of a clean override. Using new Headers(init?.headers) plus .set() is the correct fix since Headers is case-insensitive by spec, and it naturally preserves the "host wins" precedence you want.
The diff is small and the removal of plainHeaders is reasonable since it's unused once you merge through Headers directly.
Test changes look right: extending the existing hook test to return Authorization: 'Bearer host-token' and asserting the merged result replaces rather than concatenates is exactly the regression coverage this needs. Checking that user-agent survives is a nice touch to confirm the merge doesn't clobber unrelated SDK headers.
One thing to double check before porting: new Headers(init?.headers) will throw if init.headers is some exotic non-standard shape the SDK permits (e.g. a plain object with non-string values) — worth confirming init?.headers is always a valid HeadersInit at this call site, since the old plainHeaders helper defensively handled arrays/instances/objects. If that invariant already holds elsewhere in the codebase this is a non-issue.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem / Why
requestHeadersmerges the SDK headers and host headers with object spread, so differently cased spellings remain separate object keys. A host returningAuthorizationalongside the SDK's normalizedauthorizationsends a comma-joined pair of bearer values instead of replacing the old value. Real localhost probes against the current source on both Bun and Node receive HTTP 401 for that request.HTTP field names are case-insensitive; the Fetch header set operation replaces existing values for the same name. The host already takes precedence when it uses the same casing.
Changes
Merge through
Headersandset()instead of a plain object, and remove the unused conversion helper. Extend the existing request-header test to cover the mixed-case override while retaining its exact-body assertion and checking an unrelated SDK header survives. No test file or extra test case is added.Verification
Bearer tok, Bearer host-token), then 1 pass / 0 fail.okstream. No production backend or model is called. The Node probe bundles the current source for execution; it is not a published SDK build.ts.sys.getCurrentDirectoryerror. Binary build and smoke were not run because SDK build is a prerequisite.Scope / Tradeoffs
Source-audit fix, with no existing issue claimed. Two SDK files only. This preserves the existing host-overrides-default policy while applying it consistently across casing; it does not add a new authentication policy or credential store. Existing hook omission/error behavior and the BYOK exclusion remain covered by the current tests.